import type { ProColumns } from '@ant-design/pro-components';
import { ProTable } from '@ant-design/pro-components';
import styles from './index.less';
// import type { FileRuleOTD } from '@/services/types/rulesCenter/modelManagement';
import { Space } from 'antd';
import { history, useModel } from 'umi';
import hooks from '../../hooks';
const selectStatus = (status: string | undefined) => {
  switch (status) {
    case 'UNCLAIMED':
      return {
        color: 'processing',
      };
    case 'CLAIMED':
      return {
        color: 'success',
      };
  }
};
export default () => {
  const {
    formRef,
    // deleteRule,
    getTableList,
  } = hooks.useContainer();
  const { setName, actionRef, setSelectedKeys } = useModel('useTree', (model) => {
    return {
      setName: model.setName,
      setSelectedKeys: model.setSelectedKeys,
      actionRef: model.actionRef,
    };
  });

  const getParseJson = (data: any[]) => {
    if (!data) return '-';
    try {
      const arr = data?.map((item: { id: string; name: string }) => item?.name);
      return arr.join('、');
    } catch (error) {
      return data;
    }
  };
  const tableColumns: ProColumns<any>[] = [
    {
      title: '序号',
      width: 60,
      hideInSearch: true,
      renderText: (_: any, __: any, index: number) => index + 1,
    },
    {
      title: '数据资源编码',
      dataIndex: 'code',
      width: 200,
      hideInSearch: true,
    },
    {
      title: '数据资源名称',
      dataIndex: 'name',
      ellipsis: true,
      width: 180,
    },
    {
      title: '数据资源提供方',
      dataIndex: 'sourceOrgName',
      ellipsis: true,
      width: 146,
      search: false,
    },
    {
      title: '所属应用',
      dataIndex: 'apps',
      ellipsis: true,
      search: false,
      render: (_: any, record: any) => <>{getParseJson(record?.apps)}</>,
    },
    {
      title: '知识领域分类',
      dataIndex: 'knowledgeCatalogDomainName',
      ellipsis: true,
      hideInSearch: true,
    },

    {
      title: '创建时间',
      dataIndex: 'createTime',
      ellipsis: false,
      width: 160,
      valueType: 'dateTimeRange',
      search: {
        transform: (value) => {
          return {
            createTimeStart: value[0],
            createTimeEnd: value[1],
          };
        },
      },
    },
    {
      title: '操作',
      width: 100,
      dataIndex: 'operate',
      hideInSearch: true,
      renderText: (text, record) => {
        return (
          <Space size="small" className={styles.spaceWrap}>
            <a
              onClick={() => {
                history.push(
                  {
                    pathname: '/catalogue/detail',
                  },
                  {
                    id: record.id,
                  },
                );
              }}
            >
              查看详情
            </a>
          </Space>
        );
      },
    },
  ];

  return (
    <ProTable
      actionRef={actionRef}
      formRef={formRef}
      columns={tableColumns}
      form={{
        ignoreRules: false,
      }}
      request={getTableList.runAsync}
      size="middle"
      rowKey="id"
      search={{
        labelWidth: 'auto',
      }}
      onReset={() => {
        setName('');
        setSelectedKeys([]);
      }}
      pagination={{
        showSizeChanger: true,
        defaultPageSize: 10,
      }}
    />
  );
};
